package cn.wolfcode.handle;

import cn.wolfcode.domain.OrderInfo;
import cn.wolfcode.redis.SeckillRedisKey;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import top.javatool.canal.client.annotation.CanalTable;
import top.javatool.canal.client.handler.EntryHandler;

/**
 * @author hkj
 * @email 1349091387@qq.com
 * @date 2022/1/3
 * 源码允许修改，并且本人十分乐意有 大佬 来对代码进行 随 意 调 教
 **/
@Slf4j
@Component
@CanalTable(value = "t_order_info")
public class OrderInfoHandle implements EntryHandler<OrderInfo> {

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Override
    public void insert(OrderInfo orderInfo) {
        //System.out.println(orderInfo);
        redisTemplate.opsForHash().put(SeckillRedisKey.SECKILL_ORDER_HASH.getRealKey(""),orderInfo.getOrderNo(), JSON.toJSONString(orderInfo));
        System.out.println("插入");
    }

    @Override
    public void update(OrderInfo before, OrderInfo after) {
        //System.out.println(before);
        //System.out.println(after);
        redisTemplate.opsForHash().put(SeckillRedisKey.SECKILL_ORDER_HASH.getRealKey(""),after.getOrderNo(),JSON.toJSONString(after));
        System.out.println("更新");
    }

    @Override
    public void delete(OrderInfo orderInfo) {
        System.out.println(orderInfo);
        System.out.println("删除");
    }
}
